package com.learn.temp.JVM;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author wangxing
 * @version 2020/7/6 5:21 Administrator
 */
public class StringConstantDemo {
    public static void temp1() {
        String s1 = new String("ja") + new String("va");
        String s2 = s1.intern();
        System.out.println(s1 == s2);
    }

    //执行前一定要设置JVM的参数，调整小堆的容量，不然会卡死
    public static void temp2() {
        int size = 100000000;
        System.out.println("start");
        List<String> list = new LinkedList<>();
        for (int i = 0; i < size; i++) {
            list.add((new StringBuilder().append("String demo ").append(1).toString()).intern());
        }
        System.out.println("end");
    }

    public static void main(String[] args) throws IOException {
        temp2();

    }
}
